package com.wlz.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wlz
 * @date 2022-07-05  10:05 下午
 */
@Slf4j
@RestController
public class KafkaController {

    private final static String TOPIC_NAME = "kafka-spring-boot-topic";

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @RequestMapping("/send")
    public String send(String msg) throws Exception {
        SendResult<String, String> sendResult = kafkaTemplate.send(TOPIC_NAME, 0, "key", msg).get();
        return sendResult.toString();
    }


}
